<?php
class BankPage extends Page {
}
class BankPage_Controller extends Page_Controller {
	public function init() {
		parent::init();
		Requirements :: javascript("themes/cards/js/jquery.main.js");
	}
	public function getType(){
		$locale=$this->current_lang();
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
			"*",
			"Name_$locale as Title"
		);
		$sqlQuery->from = array("CardType");
		$sqlQuery->where = array("Status=1");
		$sqlQuery->orderby("Created DESC");
		// get the raw SQL
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		$URLSeg = Lib::getURLSegmentByClassName('BankPage');
		foreach($result as $row) {
			$row['Link']=$URLSeg;
			$row['getCategoty']=BankPage_Controller::getCategoty($row['ID']);
			$dataObject->push(new ArrayData($row));
		}
		if($dataObject)
		return $dataObject;
	}
	public function getcat()
	{
		$typeId=isset($_GET["tid"])?$_GET["tid"]:false;
		if($typeId){
			$locale=$this->current_lang();
			$sqlQuery = new SQLQuery();
			$sqlQuery->select = array(
			"*",
			"Name_$locale as Title"
			);
			$sqlQuery->from = array("Categories");
			$sqlQuery->where = array("Status=1 and TypeID=$typeId");
			$sqlQuery->orderby("Created DESC");
			// get the raw SQL
			$rawSQL = $sqlQuery->sql();
			$result = $sqlQuery->execute();
			$dataObject = new DataObjectSet();
			$URLSeg = Lib::getURLSegmentByClassName('BankPage');
			$tmp="<option value='%s'>%s</option>";
			$output="";
			foreach($result as $row) {
				$value=$URLSeg."/cat/".$row['ID'];
				$output.=sprintf ($tmp,$value,$row['Title']);

			}
			if($output){
				return $output;
			}else{
				return sprintf($tmp,"","");
			}
		}
	}
	public function getCategoty($typeId){
		$locale=$this->current_lang();
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
			"*",
			"Name_$locale as Title"
		);
		$sqlQuery->from = array("Categories");
		$sqlQuery->where = array("Status=1 and TypeID=$typeId");
		$sqlQuery->orderby("Created DESC");
		// get the raw SQL
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		$URLSeg = Lib::getURLSegmentByClassName('BankPage');
		foreach($result as $row) {
			$row['Link']=$URLSeg."/cat/".$row['ID'];
			$dataObject->push(new ArrayData($row));
		}
		if($dataObject)
		return $dataObject;
	}
	public function getProduct()
	{
		if (!isset ($_GET['start']) || !is_numeric($_GET['start']) || (int) $_GET['start'] < 1)
		$_GET['start'] = 0;
		$SQL_start = (int) $_GET['start'];
		$locale=$this->current_lang();
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
			"p.ID as ID",
			"p.*",
	     	"p.Name_$locale as Title",
			"p.Summary_$locale as Summary",
			"p.Content_$locale as Content", 
			"p.ImageID as ImageID",
		);
		$sqlQuery->from = array("Products p");
		$sqlQuery->where = array("Status=1");
		$sqlQuery->orderby("p.Created DESC");
		$sqlQuery->limit = "$SQL_start,4";
		// get the raw SQL
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		$URLSeg = Lib::getURLSegmentByClassName('BankPage');
		foreach($result as $row) {
			$row['Link']=$URLSeg."/show/".$row['ID'];
			$row['LinkCom']=$URLSeg."/comp";
			$row['Image']= Lib::getImages($row['ImageID']);
			$dataObject->push(new ArrayData($row));
		}
		if($dataObject)
		$dataObject->parseQueryLimit($sqlQuery);
		return $dataObject;
	}
	public function getProductById()
	{
		$params = Controller::curr()->getURLParams();
		$id = (isset($params)) ? $params['ID'] : false;
		
		$locale=$this->current_lang();
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
			"p.ID as ID",
			"p.*",
	     	"p.Name_$locale as Title",
			"p.Summary_$locale as Summary",
			"p.Content_$locale as Content", 
			"p.ImageID as ImageID",
		);
		$sqlQuery->from = array("Products p");
		$sqlQuery->where = array("Status=1 and p.ID=$id");
		// get the raw SQL
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		$URLSeg = Lib::getURLSegmentByClassName('BankPage');
		foreach($result as $row) {
			$row['Link']=$URLSeg."/show/".$row['ID'];
			$row['LinkCom']=$URLSeg."/comp";
			$row['Image']= Lib::getImages($row['ImageID']);
			$dataObject->push(new ArrayData($row));
		}
		if($dataObject)
		$dataObject->parseQueryLimit($sqlQuery);
		return $dataObject;
		Requirements :: javascript("themes/cards/js/jquery.main.js");

	}
	public function getProduct()
	{
		if (!isset ($_GET['start']) || !is_numeric($_GET['start']) || (int) $_GET['start'] < 1)
		$_GET['start'] = 0;
		$SQL_start = (int) $_GET['start'];
		$locale=$this->current_lang();
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
			"p.ID as ID",
			"p.*",
	     	"p.Name_$locale as Title",
			"p.Summary_$locale as Summary",
			"p.Content_$locale as Content", 
			"p.ImageID as ImageID",
		);
		$sqlQuery->from = array("Products p");
		$sqlQuery->where = array("Status=1");
		$sqlQuery->orderby("p.Created DESC");
		$sqlQuery->limit = "$SQL_start,4";
		// get the raw SQL
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		$URLSeg = Lib::getURLSegmentByClassName('BankPage');
		foreach($result as $row) {
			$row['Link']=$URLSeg."/show/".$row['ID'];
			$row['Image']= Lib::getImages($row['ImageID']);
			$dataObject->push(new ArrayData($row));
		}
		if($dataObject)
		$dataObject->parseQueryLimit($sqlQuery);
		return $dataObject;
	}
}